window.onload = function () {
    new lazy({
        attr: "data",
        th: 200,
        prop: "delay"
    });

    new Vue({
        el: ".left-nav",
        data() {
            return {
                linkList: [[], []],
                index: 0,
                time: null,
            }
        },
        mounted() {
            this.format(left_leaf);
            new SimSwiper("#slide", {
                autoplay: 4300,
                button: {
                    prev: "#J_pre", // 前进后退按钮
                    next: "#J_next"
                },
                loop: true,
                lazy: {
                    prop: "_src"
                },
                pagination: {
                    el: ".pagination",
                    click: true, // 是否可以点击
                }
            })
        },
        methods: {
            stop(e) {
                e.stopPropagation()
            },
            format(list) {
                for (let i = 0; i < list.length; i++) {
                    if (i % 3 !== 0) {
                        this.linkList[parseInt(i / 3)].push(list[i])
                    } else {
                        this.linkList.push([])
                        this.linkList[parseInt(i / 3)].push(list[i])
                    }
                }
                this.linkList.length -= 2;
                left_leaf = null;
            },
            fadeIn(el) {
                let o = 0;
                el.style.display = "block"
                el.style.opacity = o;
                let time = setInterval(() => {
                    o += 0.024
                    if (parseInt(o) === 1) {
                        clearTimeout(time)
                        o = 1;
                    }
                    el.style.opacity = o;
                }, 1)
            },
            fade() {
                let t_node = this.$refs['content'];
                for (let k in t_node) {
                    this.fadeOut(t_node[k])
                }
            },
            fadeOut(el) {
                el.style.display = "none"
                el.style.opacity = 0;
            },
            loadItem(i, n) {
                let t_node = this.$refs['content'];
                for (let k = 0; k < t_node.length; k++) {
                    k === i ? this.fadeIn(t_node[k]) : this.fadeOut(t_node[k]);
                }
            }
            //显示左侧栏内容
        }
    })

//第二轮播初始化
    new Vue({
        el: '.tb-slide-two',
        data() {
            return {
                end: false,
                list: [],
                index: 1,
                max: 0
            }
        },
        methods: {
            async api() {
                return await axios({
                    url: '/media/swiper',
                    method: "GET",
                })
            },
            load(currentTab) {
                let node = document.getElementsByClassName("tb-slide-two-item")[currentTab];
                let ch = node.childNodes;
                for (let i = 0; i < ch.length; i++) {
                    ch[i].firstChild.src = ch[i].firstChild.getAttribute("data")
                }
            }
        },
        mounted() {
            const t = this;
            t.api().then(e => {
                let t_data = e.data;
                try {
                    for (let i = 0; i < t_data.length; i++) {
                        let arr = [];
                        if (i % 2 !== 0) {
                            arr.push(t_data[i])
                            arr.push(t_data[i - 1])
                            this.list.push(arr)
                        }
                    }
                } catch (e) {
                }
            }).then(() => {
                new SimSwiper("#slide_two", {
                    autoplay: 4300,
                    button: {
                        prev: "#J_pre_t", // 前进后退按钮
                        next: "#J_next_t"
                    },
                    loop: true,
                    lazy: {
                        prop: "data"
                    }
                });
            })
        }
    })
        //新闻初始化
    new SimSwiper("#msg_swiper", {
        loop: true,
        lazy:false,
        autoplay:3800
    });
    //重置窗口大小
    const size = {
        init: function () {
            window.addEventListener("resize", function () {
                resize();
            })
            var resize = function () {
                let pattern = /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i;
                if (navigator.userAgent.match(pattern)) {
                    return false;
                }
            }
        }
    };
    size.init();
//导航器
    new Vue({
        el: ".jFrame",
        data: {
            float: false
        },
        mounted() {
            const doc = document, t = this,
                s_nav = doc.getElementsByClassName("search-nav")[0],
                innerContent = document.getElementsByClassName("inner-content")[0];
            window.addEventListener("scroll", function () {
                let sTop = doc.documentElement.scrollTop
                if (sTop - (s_nav.offsetTop) > 0) {
                    s_nav.classList.add("fixed");
                }
                if (sTop <= 54) {
                    s_nav.classList.remove("fixed");
                }
            })
        },
        methods: {
            scrollTo(el) {
                document.querySelector(el).scrollIntoView({behavior: 'smooth',easing:"swing"});
            },
            top() {
                document.body.scrollIntoView({offset:0,behavior: 'smooth',easing:"swing"});
            }
        }
    });
//滚动页面返回顶部
    new Vue({
        el: ".top-item",
        data() {
            return {
                show: false,
                area: ["全球", "中国大陆", "中国香港", "中国台湾", "中国澳门", "韩国", "马来西亚", "澳大利亚", "新加坡", "新西兰", "加拿大", "美国", "日本"],
                visible: false
            }
        },
        methods: {
            hide() {
                this.visible = !0;
            },
            Visi() {
                this.visible = !1;
            },
            out() {
                Cookies.remove("u_pw");
                Cookies.remove("u_id");
                Cookies.remove("td_session");
                axios.post("/logout").then(e => location.reload()).catch(err => console.log(err));
            },
            fadeIn() {
                this.show = true;
            }, fadeOut() {
                this.show = false;
            }
        }
    })
}